<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var twoSum = function (nums, target) {
        let map = new Map();
        for (let i = 0; i < nums.length; i++) {
          map.set(nums[i], i);
        }
        console.log(map);
        //map {3:1}    最后 i==0   map.get(3) ==1 所以重复无所谓
        for (let i = 0; i < nums.length; i++) {
          let x = target - nums[i];
          if (map.has(x) && i !== map.get(x)) {
            return [map.get(x), i];
          }
        }
      };
    </script>
  </body>
</html>
